package com.niuxiaofa.newlaw.Activity;

import android.widget.Toast;

import androidx.recyclerview.widget.RecyclerView;

import com.niuxiaofa.newlaw.Base.BaseActivity;
import com.niuxiaofa.newlaw.Bean.TaskBean;
import com.niuxiaofa.newlaw.Network.ApiService;
import com.niuxiaofa.newlaw.Network.ServiceManager;
import com.niuxiaofa.newlaw.R;
import com.niuxiaofa.newlaw.Tools.RecyclerViewHelp;
import com.niuxiaofa.newlaw.Tools.UIUtils;
import com.niuxiaofa.newlaw.adapter.MedalMissionAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


/**
 * 勋章任务
 */
public class MedalMissionActivity extends BaseActivity {


    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;

    List<TaskBean.DataDTO> newsList=new ArrayList<>();

    MedalMissionAdapter medalMissionAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_medalmission;
    }

    @Override
    protected void initData() {

        Call<TaskBean> call = ServiceManager.getInstance().creat(ApiService.class).tasklist();

        call.enqueue(new Callback<TaskBean>() {
            @Override
            public void onResponse(Call<TaskBean> call, Response<TaskBean> response) {
                //判断请求是否成功
                if (response.isSuccessful()) {
                    TaskBean baseBean = (TaskBean) response.body();
                    if (baseBean.getCode()==1){
                        newsList.addAll(baseBean.getData());
                        medalMissionAdapter.notifyDataSetChanged();


                    }

                }
            }

            @Override
            public void onFailure(Call<TaskBean> call, Throwable t) {
//            Log.e("链接错误", t.getMessage());
                Toast.makeText(UIUtils.getActivity(),"网络连接异常,请稍候在试",Toast.LENGTH_LONG).show();
            }
        });




        medalMissionAdapter=new MedalMissionAdapter(newsList, new MedalMissionAdapter.Onclick() {
            @Override
            public void onclick(int c) {

            }
        });

        RecyclerViewHelp.setRecycler(recyclerview,0).setAdapter(medalMissionAdapter);


    }
}
